package com.sskj.ffex.p.activity;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.ffex.MyAppLication;
import com.sskj.ffex.m.HttpConfig;
import com.sskj.ffex.m.bean.AppVersionBean;
import com.sskj.ffex.m.bean.HttpData;
import com.sskj.ffex.m.http.JsonCallBack;
import com.sskj.ffex.p.base.BasePresenter;
import com.sskj.ffex.utils.APKVersionCodeUtils;
import com.sskj.ffex.utils.ToastUtil;
import com.sskj.ffex.v.activity.GoogleSettingActivity;

/**
 * <pre>
 *     author : wk_math
 *     e-mail : wk_math@163.com
 *     time   : 2018/03/30
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class GoogleSettingPresenter extends BasePresenter<GoogleSettingActivity> {

    public void setType(int type) {
        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.OPEN_TYPE)
                .params("act", type)
                .execute(new JsonCallBack<HttpData<String>>(this) {
                    @Override
                    protected void _onSuccess(Response<HttpData<String>> response) {
                        ToastUtil.showShort(response.body().msg);
                        mView.updateUiSuccess(type);
                    }
                });
    }

    public void getVersion() {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.VERSION)
                .tag(mView)
                .params("version", APKVersionCodeUtils.getVerName(MyAppLication.getApplication()))
                .params("type", "1")
                .tag(mView)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void _onSuccess(Response<HttpData> response) {
                        HttpData<AppVersionBean> httpData = response.body();
                        if (httpData.getStatus()==200){
                            mView.onVersionDataSuccess(httpData.getData());
                        }else{
                            ToastUtil.showShort(httpData.getMsg());
                        }
                    }
                });

    }
}
